<?php
require_once 'class/game.php';
//header('Access-Control-Allow-Origin:*');
$sess = new \main\sess();
$sess->startSession();

$user = new \main\user();
$game = new \main\game();

$a = '';

if ( isset($_POST[ 'submit']) ){

    $username = $_POST['username'];
    $userpass = $_POST['userpass'];
    $Obj_login_user = $user->login_user($username , $userpass);
    if (!$Obj_login_user){
        exit('error');
    }

    if ($Obj_login_user->status == 0){
        $msg = $Obj_login_user->msg;
    }else{

        $userinfo = $Obj_login_user->obj;
        $_SESSION['token'] = $userinfo->token;

        $Obj_login_game = $user->login_game();

        //var_dump($Obj_login_game);
        if (!$Obj_login_game){
            exit('error');
        }

        if ($Obj_login_game->status == 0 ){
            $msg = $Obj_login_user->msg;
        }

        if ($Obj_login_game->status == 2 ){
            Header("Location:chuangjian.php");
            exit();
        }

        if ($Obj_login_game->status == 1 ){
            $uinfo = $Obj_login_game->obj;
            $_SESSION['sid'] = $uinfo->sid;
            $_SESSION['uid'] = $uinfo->uid;

            Header("Location:./game.php");
            exit();
        }

    }

}

$game_name = $game->get_system_config("系统","游戏名称");
if(!$game_name){ $game_name = "无名游戏"; }

?>
<html lang="en">
<head>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title><?php echo $game_name ?></title>
    <link rel="stylesheet" href="css/gamecss.css?_=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/h5ui.min.css?_=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/example.min.css?_=<?php echo time(); ?>">
</head>
<body>
<div class="h5ui-page spacing-cell">

    <img class="lazyload" src="images/11.jpg" data-original="images/11.jpg" width="100%" alt="">

    <div class="h5ui-msg_content">
        <h3>
            月冷千山江自碧，冰崖万丈无留意。<br/>
            寻道只影莲花落，竹音寥落听新曲。<br/>
            仙人听谁醉明月，踏浪踏风随燕去。<br/>
            纪纲人伦心如桑，一醉红尘消百绪。<br/>
            魔前扣首三千年，回首红尘不做仙。<br/>
        </h3>
    </div>

    <div class="h5ui-form ">
        <form method="post">

            <label for="username" class="h5ui-form-label">账号</label>
            <input type="text" name="username" class="h5ui-form-input" placeholder="请输入账号">
            <br/>
            <label for="password" class="h5ui-form-label">密码</label>
            <input type="password" name="userpass" class="h5ui-form-input" placeholder="请输入密码">
            <br/>
            <div class="h5ui-msg_content"  style="color: red"><?php if (isset($msg)){ echo $msg;} ?></div>
            <br/>
            <div align="center">
                <p>
                    <button class="h5ui-btn h5ui-btn_primary btn-outlined" type="submit" name="submit" >登陆</button>
                </p>

                <p>
                    <a class="h5ui-btn h5ui-btn_primary btn-outlined" href="reguser.php" >注册</a>
                </p>
            </div>



        </form>

    </div>
<br/>
</div>

</body>
</html>